﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using phpBB;

namespace WebApplication1
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            phpBBMembershipProvider MembershipService = Membership.Provider as phpBBMembershipProvider;
            string UserName = "";
            bool rememberMe = false;

            if (MembershipService.IsAuthenticated(out UserName, out rememberMe))
            {
                if (!MembershipService.FormsIsAuthenticated())
                {
                    FormsAuthentication.SetAuthCookie(UserName, rememberMe);
                    MembershipService.ReloadPage();
                }
            }
            else
            {
                if (MembershipService.FormsIsAuthenticated())
                {
                    FormsAuthentication.SignOut();
                    MembershipService.ReloadPage();
                }
            }
        }

        protected void Login1_LoggedIn(object sender, EventArgs e)
        {
            Login loginControl = sender as Login;
            (Membership.Provider as phpBBMembershipProvider).LogOn(loginControl.UserName, loginControl.RememberMeSet);
        }

        protected void LoginStatus1_LoggedOut(object sender, EventArgs e)
        {
            (Membership.Provider as phpBBMembershipProvider).SignOut();
        }
    }
}
